package cn.qy.kotlin.base.ch12

/**
 * 方格 Room 类
 */
// 给 Room 类添加 open 关键字
open class Room(val name: String) {
    // 表示某个地方的危险级别，取值范围是 1~10
    protected open val dangerLevel = 5

    fun description() = "Room: $name"
    // 先以 open 关键字修饰，然后子类才能覆盖它
    open fun load() = "Nothing much to see here..."
}

open class TownSquare : Room("Town Square") {
    override val dangerLevel = super.dangerLevel - 3
    private var bellSound = "GWONG"
    // 给被继承的函数加上 final 关键字，就是保证它不被下级子类覆盖
    final override fun load() = "The villagers rally and cheer as you enter!\n${ringBell()}"

    private fun ringBell() = "The bell tower announces your arrival. $bellSound"
}

// 如果要继承 TownSquare，则必须使得 TownSquare 开放 open 才行
class Piazza : TownSquare() {
}